/**
 * Created by sun on 2016/8/4.
 */
define(function (require) {
    var app = require('/../js/app');
    require('ui-table');


    app.useModule("ui.table");


    var datepicker = require('datepicker');

    app.controller('invite_incomeCtrl', ['$scope','$http',"$filter" ,function ($scope, $http,$filter) {
        $scope.orderParams = {
            url: "/admin/inviteIncome/list"
        };
        datepicker($scope);
        $scope.ctrlScope=$scope;
        $scope.check={};

        //创建页面
        $scope.addOrderModal=function(){
            $scope.orderModal = !$scope.orderModal;
        };

//查看
        $scope.checkDetail= function (id) {
            $scope.check={};
            $scope.detailModal = !$scope.detailModal;
            $http({
                method: 'POST',
                url: "/admin/inviteIncome/getSingle",
                data:{id:id},
            }).success(function(data) {
                console.info(data);
                $scope.check=data

            }).error(function(data) {
            });

        };
        //全局查询
        $scope.search = function() {
            $scope.ctrlScope.itemsearch.beginDateTime=$scope.ctrlScope.itemsearch.beginDateTimex;
            $scope.ctrlScope.itemsearch.endDateTime= $scope.ctrlScope.itemsearch.endDateTimex;
            $scope.ctrlScope.itemsearch.beginDateTime=$filter('date')($scope.ctrlScope.itemsearch.beginDateTime,'yyyy-MM-dd');
            $scope.ctrlScope.itemsearch.endDateTime=$filter('date')($scope.ctrlScope.itemsearch.endDateTime,'yyyy-MM-dd');
            //表格查询参数设置
            $scope.orderParams.ajaxParam=$scope.ctrlScope.itemsearch;
            //表格刷新
            $scope.orderParams.reload();
        };

        //全局查询重置
        $scope.reset=function(){
            $scope.ctrlScope.itemsearch={};
            $scope.orderParams.ajaxParam={};
            $scope.orderParams.reload();
        };

        //创建
        $scope.submit = function(){
        	var parm= $scope.add;
            $http({
                method: 'POST',
                url: "/admin/inviteIncome/add",
                data:parm,
            }).success(function(data) {
                console.info(data);
                alert("创建成功！");
                $scope.orderModal = !$scope.orderModal;
                $scope.orderParams.reload();
            }).error(function(data) {
            });
        };


        //导出
        $scope.download=function(){
            var params=$scope.ctrlScope.itemsearch;
            $http.post("/admin/inviteIncome/excel",params)
                .success(function (data){
                    console.info(data);
                    if(data.result=="success"){
                        window.open(data.file);
                    }else{
                        toastr.error("导出失败");
                    }
                }).error(function(data){

                });
        };

    }]);


});